/*****************************************************************************
*        描述 :
*             文件描述
*        CLR版本:            3.5
*        创建者 :            蒋 光
*        个人域名:           jiangguang.net.cn
*        命名空间名称:       ECP.DataAccess
*        文件名:             BaseAccreditDao.cs
*        创建系统时间:       2012/11/2 19:06:59
*        创建年份:           2012
*
/*****************************************************************************/

namespace ECP.DataAccess
{
    using System.Data;
    using ECP.DataAccess.Utilities;
    using ECP.Model;
    using ECP.Utilities;

    public class BaseAccreditDao : BaseDao
    {
        public BaseAccreditDao()
        {
        }

        public BaseAccreditDao(IDbHelper dbHelper)
            : this()
        {
            base.DbHelper = dbHelper;
        }

        public BaseAccreditDao(IDbHelper dbHelper, BaseUserInfo userInfo)
            : this(dbHelper)
        {
            base.UserInfo = userInfo;
        }

        public DataTable GetAccredit(string staffID, string targetStaffID)
        {
            DataTable dataTable = new DataTable(BasePermissionTable.TableName);
            string sqlQuery = "  SELECT " + BasePermissionTable.TableName + ".*   FROM " + BasePermissionTable.TableName + "    WHERE " + BasePermissionTable.TableName + "." + BasePermissionTable.FieldEnabled + " = 1           AND " + BasePermissionTable.TableName + "." + BasePermissionTable.FieldID + "              IN ( SELECT " + BaseResourcePermissionTable.FieldPermissionID + "                     FROM " + BaseResourcePermissionTable.TableName + "                    WHERE " + BaseResourcePermissionTable.FieldResourceID + " = '" + targetStaffID + "'                          AND " + BaseResourcePermissionTable.FieldResourceCategory + " = 'User'                          AND " + BaseResourcePermissionTable.FieldCreateUserID + "='" + staffID + "') ORDER BY " + BasePermissionTable.TableName + "." + BasePermissionTable.FieldSortCode;
            base.DbHelper.Fill(dataTable, sqlQuery);
            return dataTable;
        }

        public DataTable GetPermissionList()
        {
            BasePermissionAdminDao dao = new BasePermissionAdminDao(base.DbHelper, base.UserInfo);
            if (base.UserInfo.IsAdministrator)
            {
                return dao.GetDT();
            }
            string[] licensePermissionIDs = new BaseUserPermissionScopeDao(base.DbHelper, base.UserInfo).GetLicensePermissionIDs(base.UserInfo.ID);
            return dao.GetDT(licensePermissionIDs);
        }
    }
}